// import store from "../store/index.js"
import functions from "@/utils/functions.js";

let tipState = true;


/**
 * 获取token
 */
export function getToken() {

	return uni.getStorageSync('token') || ""

}

/**
 * 设置token
 * @param {Object} token
 */
export function setToken(token) {

	uni.setStorageSync('token', token)
}



/**
 * 获取token
 */
export function getRefreshToken() {

	return store.state.moduleAuth.refreshToken || ""

}

/**
 * 设置setRefreshToken
 * @param {Object} token
 */
export function setRefreshToken(token) {

	store.commit('setRefreshToken', token)
}



/**
 * 退出登录
 */
export function logout() {

	if (tipState) {
		tipState = false;
		
		var pages = getCurrentPages();//当前页
		console.log("pages",pages);
		console.log("上个页面",pages[pages.length - 1].$page.fullPath);
		let url = "";
		if(pages[pages.length - 1].$page.fullPath != '/pages/show/index'){
			url = encodeURIComponent(pages[pages.length - 1].$page.fullPath)
		}
		uni.showModal({
			title: '提示',
			content: "您还未登录，是否前往登录？",
			success: (res) => {
				if (res.confirm) {
					store.commit('moduleAuth/setUserId', 0)
					uni.reLaunch({
						url: "/pages/login/index?url="+url
					})
					tipState = true;
				} else {
					tipState = true;
				}
			},
			fail: () => {
				tipState = true;
			}
		});
	}
}